package com.atguigu.gulimall.product.service.impl;

import com.atguigu.gulimall.product.entity.MusersEntity;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.Query;

import com.atguigu.gulimall.product.dao.MshoppingcartDao;
import com.atguigu.gulimall.product.entity.MshoppingcartEntity;
import com.atguigu.gulimall.product.service.MshoppingcartService;
import org.springframework.util.StringUtils;


@Service("mshoppingcartService")
public class MshoppingcartServiceImpl extends ServiceImpl<MshoppingcartDao, MshoppingcartEntity> implements MshoppingcartService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {


        String key = (String) params.get("key");
        QueryWrapper<MshoppingcartEntity> mshoppingcartEntityQueryWrapper = new QueryWrapper<MshoppingcartEntity>();
        if(!StringUtils.isEmpty(key)){
            mshoppingcartEntityQueryWrapper.eq("product_id",key).or().eq("user_id",key);
        }

        IPage<MshoppingcartEntity> page = this.page(
                new Query<MshoppingcartEntity>().getPage(params),
                new QueryWrapper<MshoppingcartEntity>()
        );

        return new PageUtils(page);
    }

}